<template>
  <el-form
      label-position="top"
      label-width="100px"
      :model="user"
      class="login-background"
      :style="background"
      :rules="rules"
  >
    <el-row class="login-header">
        <span class="login-log">
        <img
            :width="200"
            src="@/assets/logo.png"
        />
          </span>
    </el-row>
    <el-tabs type="border-card" activeKey="1" class="login-main">
      <el-tab-pane key="1" label="找回密码">
        <el-form-item label="手机号" v-if="isPhone" prop="phone">
          <el-input type="text" v-model="user.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" v-else prop="email">
          <el-input type="text" v-model="user.email"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="verificationCode">
          <el-row :gutter="20">
            <el-col span="22">
              <el-input v-model="user.verificationCode" type="text"></el-input>
            </el-col>
            <el-col span="2" :style="{'position':'absolute','right':'0'}">
              <el-button type="text">短信验证</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="新密码" prop="password">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item :style="{'height':'32px','line-height':'32px'}">
          <el-button v-if="isPhone" type="text" @click="isPhone=!isPhone">邮箱登陆</el-button>
          <el-button v-else type="text" @click="isPhone=!isPhone">手机登陆</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :style="{'width':'100%'}">修改密码</el-button>
        </el-form-item>
      </el-tab-pane>
    </el-tabs>
  </el-form>
</template>

<script>
import { defineComponent, reactive, ref } from 'vue'
import { checkEmail, checkPassword, checkPhone, checkVerificationCode } from '../utils/validator'

export default defineComponent({
  name: 'ResetPassword',
  setup () {
    const user = reactive({
      phone: '',
      email: '',
      verificationCode: '',
      password: ''
    })
    const isPhone = ref(true)
    return {
      user,
      isPhone,
      background: {
        background: 'url(' + require('@/assets/login-background.svg') + ')',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center 110px',
        backgroundSize: '100%'
      },
      rules: {
        phone: [{
          required: true,
          validator: checkPhone,
          trigger: 'change'
        }],
        verificationCode: [{
          required: true,
          validator: checkVerificationCode,
          trigger: 'change'
        }],
        email: [{
          required: true,
          validator: checkEmail,
          trigger: 'change'
        }],
        password: [{
          required: true,
          validator: checkPassword,
          trigger: 'change'
        }]
      }
    }
  }
})
</script>

<style scoped>
.login-background {
  height: 100vh;
  padding-top: 30px;
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 15px 0;
}

.login-log {
  width: 60px;
  height: 60px;
  vertical-align: top;
}

.login-log img {
  width: 100%;
}

.login-main {
  width: 328px;
  margin: 0 auto;
}
</style>
